<?php

/* @var $this yii\web\View */

use yii\helpers\Url;
use yii\helpers\Html;
use yii\widgets\ActiveForm;
use common\helpers\Render;
use common\models\Design;

$this->addCrumbs('作品列表', 'design/design-list');
$this->title = '修改作品';
?>

<form class="box-content flyer-form pane gap" id="flyer-create" action="<?= Url::to('@web/design/design-update?id='.$data['id']) ?>" method="post">
    <div class="flyer-tabs" flyer="tabs">
        <div class="tab-header">
            <span class="header active"><i class="icon-gear"></i> 信息配置<i class="notice icon-info-circle"></i></span>
            <span class="header"><i class="icon-list-alt"></i> 作品展示<i class="notice icon-info-circle"></i></span>
        </div>
        <div class="tab-contenter">
            <div class="contenter active">
                <div class="form-item">
                    <div class="input-title">作者</div>
                    <div class="input-block input-mid"><span class="flyer-status blue thin"><i class="icon-user"></i> <?= Render::value($data, 'designer.username') ?>：<?= Render::value($data, 'designer_id') ?></span></div>
                </div>
                <div class="form-item checker">
                    <div class="input-title">标题</div>
                    <div class="input-block"><input class="flyer-input" type="text" name="title" value="<?= Render::value($data, 'title') ?>" placeholder="title."></div>
                </div>
                <div class="form-item">
                    <div class="item-inline checker">
                        <div class="input-title">分类</div>
                        <div class="input-inline"><?= Render::select('category_id[]', [], null, ['flyer' => 'select', 'id' => 'category', 'data-select' => Render::value($data, 'category_id')]) ?></div>
                    </div>
                    <div class="item-inline checker">
                        <div class="input-title">设计类型</div>
                        <div class="input-inline"><?= Render::select('model', $modelSelector, Render::value($data, 'model'), ['flyer' => 'select']) ?></div>
                    </div>
                </div>
                <div class="form-item checker">
                    <div class="input-title">作品等级</div>
                    <div class="input-inline"><?= Render::select('level', Design::$levelSelector, Render::value($data, 'level'), ['flyer' => 'select']) ?></div>
                </div>
                <div class="form-item">
                    <div class="item-inline checker">
                        <div class="input-title">上线设备</div>
                        <div class="input-inline"><?= Render::select('device', Design::$deviceSelector, Render::value($data, 'device'), ['flyer' => 'select']) ?></div>
                    </div>
                    <div class="item-inline checker">
                        <div class="input-title">上线平台</div>
                        <div class="input-inline"><?= Render::select('platform', Design::$platformSelector, Render::value($data, 'platform'), ['flyer' => 'select']) ?></div>
                    </div>
                </div>
                <div class="form-item checker">
                    <div class="input-title">设计风格</div>
                    <div class="input-block"><input class="flyer-input" type="text" name="style" value="<?= Render::value($data, 'style') ?>" placeholder="以‘；’分割，每个不能超过4个字."></div>
                </div>
                <div class="form-item checker">
                    <div class="input-title">状态</div>
                    <div class="input-inline"><?= Render::select('status', Design::$statusSelector, Render::value($data, 'status'), ['flyer' => 'select']) ?></div>
                </div>
                <div class="form-item checker item-text">
                    <div class="input-title">备注</div>
                    <div class="input-block"><textarea class="flyer-textarea" name="remark" placeholder="remark."><?= Render::value($data, 'remark') ?></textarea></div>
                </div>
                <div class="form-item">
                    <div class="item-inline checker">
                        <div class="input-title">浏览量</div>
                        <div class="input-inline"><input class="flyer-input" type="text" name="view" value="<?= Render::value($data, 'view', 0) ?>" placeholder="view."></div>
                    </div>
                    <div class="item-inline checker">
                        <div class="input-title">收藏量</div>
                        <div class="input-inline"><input class="flyer-input" type="text" name="collection" value="<?= Render::value($data, 'collection', 0) ?>" placeholder="collection."></div>
                    </div>
                </div>
            </div>
            <div class="contenter">
                <div class="data-title mb-10px"><i class="icon-bar-chart"></i> 缩略图</div>
                <div class="form-item checker">
                    <div id="thumb"></div>
                    <input id="thumb-input" name="thumb" type="text" value="<?= Render::value($data, 'thumb') ?>" style="display:none;">
                </div>
                <div class="data-title mt-20px mb-10px"><i class="icon-picture"></i> 作品图片</div>
                <div class="form-item checker">
                    <div id="uploader"></div>
                    <input id="image-input" name="image" type="text" value="<?= Render::value($data, 'image') ?>" style="display:none;">
                </div>
            </div>
        </div>
    </div>
    <div class="form-item mt-10px">
        <div class="input-block tr bdn"><button class="flyer-button normal border-round" id="save-button" type="submit"><i class="icon-save"></i> 保 存</button></div>
        <textarea id="flyer-create-json" data-form="#flyer-create" style="display:none;"><?= Design::checker('admin') ?></textarea>
    </div>
    <input type="hidden" name="_csrf" value="<?=Yii::$app->request->getCsrfToken() ?>">
</form>

<script src="<?= Render::static('flyer/flyer.class.js') ?>"></script>
<script src="<?= Render::static('flyer/checker.class.js') ?>"></script>
<script src="<?= Render::static('system/category-design.data.js') ?>"></script>
<script src="<?= Render::static('flyer/categorier.class.js') ?>"></script>
<!-- 图片上传功能插件引入 -->
<link href="<?= Render::static('uploader/loader.css') ?>" rel="stylesheet">
<script src="<?= Render::static('uploader/loader.core.single.class.js') ?>"></script>
<script src="<?= Render::static('uploader/loader.image.class.js') ?>"></script>
<script>
    $(document).ready(function() {
        // 初始化Category
        (new categorier()).init({ fix: false, dom: '#category', data: DesignCategories, relate: DesignCategoriesRelation, start: '<?= Yii::$app->params['designCategories'] ?>' });
        // Form 元素初始化
        (new flyer).init({ form: '#flyer-create' });
        // 表单数据验证
        (new checker).init({ ruleDom: '#flyer-create-json' });

        // 初始化 图片上传插件
        (new loaderImage()).init({
            conter: '#thumb',
            prevLoaders: "<?= isset($data['id']) ? Render::upload(Render::value($data, 'thumb')) : '' ?>",
            action: '<?= Url::to('@web/design/design-uploader') ?>',
            onSuccess: function (file, response) {
                response = $.parseJSON(response);
                $('#thumb-input').val(response.path);
            },
            onFailure: function (file) {
                layer.alert('图片 ' + file.name + ' 上传失败！', {icon: 2});
            }
        });

        // 初始化 图片上传插件
        (new loaderImage()).init({
            conter: '#uploader',
            prevLoaders: "<?= isset($data['id']) ? Render::upload(Render::value($data, 'image')) : '' ?>",
            action: '<?= Url::to('@web/design/design-uploader') ?>',
            onSuccess: function (file, response) {
                response = $.parseJSON(response);
                $('#image-input').val(response.path);
            },
            onFailure: function (file) {
                layer.alert('图片 ' + file.name + ' 上传失败！', {icon: 2});
            }
        });
    });
</script>